package onki.tests;

import java.util.ArrayList;
import java.util.HashMap;
import onki.tests.pageObjects.OnkiStatisticsPageObject;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.PageFactory;
import org.testng.annotations.*;
import static org.junit.Assert.assertTrue;

@Test(dependsOnGroups = {"finnish"}, groups = {"statistics"})
public class YsoStatisticsCorrectness extends OnkiTestBase {

  private WebDriver driver;
  private OnkiStatisticsPageObject page;

  @BeforeClass
  public void setUp() {
    this.driver = new FirefoxDriver();
    this.page = loadConcept("fi");
  }

  public void hasProperTitle() {
    assertTrue(this.driver.getTitle().contains("YSO"));
  }

  public void hasEnglishConcepts() {
    HashMap<String, ArrayList<Integer>> rows = this.page.getConceptCountList();
    ArrayList<Integer> englishConcepts = rows.get("en");
    boolean allEmpty = true;
    for (int i=0; i < englishConcepts.size(); i++) {
      Integer current = englishConcepts.get(i);
      if (current > 0)
        allEmpty = false;
    }
    assertTrue(!allEmpty);
  }
  
  public void hasFinnishConcepts() {
    HashMap<String, ArrayList<Integer>> rows = this.page.getConceptCountList();
    ArrayList<Integer> finnishConcepts = rows.get("fi");
    boolean allEmpty = true;
    for (int i=0; i < finnishConcepts.size(); i++) {
      Integer current = finnishConcepts.get(i);
      if (current > 0)
        allEmpty = false;
    }
    assertTrue(!allEmpty);
  }
  
  public void hasSwedishConcepts() {
    HashMap<String, ArrayList<Integer>> rows = this.page.getConceptCountList();
    ArrayList<Integer> swedishConcepts = rows.get("sv");
    boolean allEmpty = true;
    for (int i=0; i < swedishConcepts.size(); i++) {
      Integer current = swedishConcepts.get(i);
      if (current > 0)
        allEmpty = false;
    }
    assertTrue(!allEmpty);
  }

  @AfterClass
  public void tearDown() {
    driver.quit();
  }

  public OnkiStatisticsPageObject loadConcept(String lang) {
    this.driver.get(baseUrl + "yso/" + lang);
    OnkiStatisticsPageObject cat = PageFactory.initElements(this.driver, OnkiStatisticsPageObject.class);
    return cat;
  }
}
